package com.guli.sta.controller;


import com.guli.sta.service.DailyService;
import com.guli.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author ZhaoZhenyu
 * @since 2022-10-05
 */

//@CrossOrigin
@RestController
@RequestMapping("/sta/daily")
public class DailyController {

    @Autowired
    private DailyService dailyService;

    /**
     * 手动创建统计数据
     * @param day
     * @return
     */
    @PostMapping("/createSta/{day}")
    public R createStatisticsByDate(@PathVariable String day) {
        dailyService.createStatisticsByDay(day);
        return R.ok();
    }

    /**
     * 根据日期和类型 传 数据到前端
     * @param begin
     * @param end
     * @param type
     * @return
     */
    @GetMapping("showChart/{begin}/{end}/{type}")
    public R showChart(@PathVariable String begin,@PathVariable String end,@PathVariable String type){
        Map<String, Object> map = dailyService.getChartData(begin, end, type);
        return R.ok().data(map);
    }

}

